package com.sky.controller.admin;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端-订单接口")
public class OrderController {
	@Autowired
	private OrderService orderService;

	@GetMapping("/conditionSearch")
	@ApiOperation("订单条件分页查询")
	public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
		log.info("订单条件分页查询：{}", ordersPageQueryDTO);
		PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
		return Result.success(pageResult);
	}

	@GetMapping("/statistics")
	@ApiOperation("统计各个状态订单数据")
	public Result<OrderStatisticsVO> statistics() {
		log.info("统计各个状态订单数据");
		OrderStatisticsVO orderStatisticsVO = orderService.statistics();
		return Result.success(orderStatisticsVO);
	}

	@PutMapping("/confirm")
	@ApiOperation("确认订单")
	public Result<Object> confirm(@RequestBody OrdersDTO ordersDTO) {
		log.info("确认订单：{}", ordersDTO);
		orderService.confirm(ordersDTO);
		return Result.success();
	}

	@GetMapping("/details/{id}")
	@ApiOperation("订单详情")
	public Result<OrderVO> details(@PathVariable("id") Long id) {
		log.info("订单详情，订单id为：{}", id);
		OrderVO orderVO = orderService.orderDetail(id);
		return Result.success(orderVO);
	}

	@PutMapping("/delivery/{id}")
	@ApiOperation("订单派送")
	public Result<Object> delivery(@PathVariable("id") Long id) {
		log.info("订单派送，订单id为：{}", id);
		orderService.delivery(id);
		return Result.success();
	}

	@PutMapping("/complete/{id}")
	@ApiOperation("订单完成")
	public Result<Object> complete(@PathVariable("id") Long id) {
		log.info("订单完成，订单id为：{}", id);
		orderService.complete(id);
		return Result.success();
	}

	@PutMapping("/rejection")
	@ApiOperation("订单拒绝")
	public Result<Object> rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
		log.info("订单拒绝：{}", ordersRejectionDTO);
		orderService.rejection(ordersRejectionDTO);
		return Result.success();
	}

	@PutMapping("/cancel")
	@ApiOperation("取消订单")
	public Result<Object> cancel(@RequestBody Orders orders) throws Exception {
		log.info("取消订单：{}", orders);
		orderService.adminCancel(orders);
		return Result.success();
	}
}
